#! /bin/sh

name=binutils
version=2.44
revision=1
tarball_url="https://ftp.gnu.org/gnu/binutils/binutils-with-gold-${version}.tar.xz"
tarball_blake2b="d749d5fbab2d6c2455bf9a988daa5c5ab9ecd9ecd63e4be022bc06483ebc996588c515ee4b931ff2ba7bcf43242068c0747e1cad50740523b2073df5a338614f"
imagedeps="build-essential"
hostdeps="gcc pkg-config"
deps="core-libs zlib zstd"

prepare() {
    autotools_recursive_regen
}

configure() {
    autotools_configure \
        --target=${OS_TRIPLET} \
        --with-build-sysroot=${sysroot_dir} \
        --enable-separate-code \
        --enable-cet \
        --enable-colored-disassembly \
        --enable-default-execstack=no \
        --enable-deterministic-archives \
        --enable-gold \
        --enable-ld=default \
        --enable-new-dtags \
        --enable-plugins \
        --enable-relro \
        --enable-threads \
        --disable-werror \
        --with-pic \
        --with-system-zlib
}

build() {
    make -j${parallelism}
}

package() {
    DESTDIR="${dest_dir}" make install

    # Remove unnecessary directory
    rm -rf "${dest_dir}${prefix}"/${OS_TRIPLET}

    # Remove static libraries
    rm -rf "${dest_dir}${prefix}"/lib/*.a

    post_package_strip
}
